package com.sky.mapper;

import com.sky.entity.OrderDetail;
import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    /**
     * 批量插入购物车数据
     * @param shoppingCarts
     */
    void insertBatch(List<ShoppingCart> shoppingCarts);

    /**
     * 根据user_id, (setmeal_id) || (dish_id, dish_flavor) 查出唯一一条购物车数据
     * @param shoppingCart
     * @return
     */
    List<ShoppingCart> list(ShoppingCart shoppingCart);

    /**
     * 插入数据
     * @param shoppingCart
     */
    @Insert("insert into sky_take_out.shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor, amount, create_time) " +
            "values(#{name}, #{image}, #{userId}, #{dishId}, #{setmealId}, #{dishFlavor}, #{amount}, #{createTime})")
    void insert(ShoppingCart shoppingCart);

    /**
     * 跟新数据
     * @param item
     */
    @Update("update sky_take_out.shopping_cart set shopping_cart.number = #{number} where id = #{id}")
    void update(ShoppingCart item);

    /**
     * 查用户购物车所有数据
     * @return
     */
    @Select("select * from sky_take_out.shopping_cart where user_id = #{currentId}")
    List<ShoppingCart> listByUserId(Long currentId);

    /**
     * 删除用户所有购物车数据
     * @param currentId
     */
    @Delete("delete from sky_take_out.shopping_cart where user_id = #{currentId}")
    void deleteByUserId(Long currentId);

    /**
     * 根据主键删除购物车一条数据
     * @param id
     */
    @Delete("delete from sky_take_out.shopping_cart where id = #{id}")
    void deleteById(Long id);
}
